package ru.spbu.math.android.cbrf.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Class for keeping data from model StockItem This class is Singleton
 * @author  Svetlana Zemlyanskaya
 */

public class StockItemStore {

    /**
	 * @uml.property  name="itemList"
	 */
    private static List<StockItem> itemList = new ArrayList<StockItem>();
    private static final int MAX_ITEMS = 5;

    /**
	 * Get StockItem List from StockItemStore
	 * @return  List<StockItem>
	 * @uml.property  name="itemList"
	 */
    public List<StockItem> getItemList() {
        return itemList;
    }

    public void addStockItem(StockItem item) {
        itemList.add(item);
    }

    public void removeItemByCode(String code) {
        // todo: removing...
    }

    public void removeItemById(String id) {
        //  todo: removing...
    }


    protected StockItemStore() {
        itemList = new ArrayList<StockItem>();
        StockItem item = new StockItem("1", "RUB", "Rubble", 1, "");
        itemList.add(item);
        item = new StockItem("2", "GBP", "British Pound Sterling", 1, "");
        itemList.add(item);
        item = new StockItem("3", "BYR", "Belarussian Ruble", 1000, "");
        itemList.add(item);
        item = new StockItem("4", "EUR", "Euro", 1, "");
        itemList.add(item);
        item = new StockItem("5", "USD", "US Dollar", 1, "");
        itemList.add(item);
        item = new StockItem("6", "DKK", "Danish Krone", 10, "");
        itemList.add(item);
        item = new StockItem("7", "ISK", "Iceland Krona", 100, "");
        itemList.add(item);
        item = new StockItem("8", "KZT", "Kazakh Tenge", 100, "");
        itemList.add(item);
        item = new StockItem("9", "CAD", "Canadian Dollar", 1, "");
        itemList.add(item);
        item = new StockItem("11", "CNY", "China Yuan", 10, "");
        itemList.add(item);
        item = new StockItem("12", "NOK", "Norwegian Krone", 10, "");
        itemList.add(item);
        item = new StockItem("13", "XDR", "SDR", 1, "");
        itemList.add(item);
        item = new StockItem("14", "SGD", "Singapore Dollar", 1, "");
        itemList.add(item);
        item = new StockItem("15", "TRY", "Turkish Lira", 1, "");
        itemList.add(item);
        item = new StockItem("16", "UAH", "Ukrainian Hryvnia", 10, "");
        itemList.add(item);
        item = new StockItem("17", "SEK", "Swedish Krona", 10, "");
        itemList.add(item);
        item = new StockItem("18", "CHF", "Swiss Franc", 1, "");
        itemList.add(item);       
        item = new StockItem("19", "JPY", "Japanese Yen", 100, "");
        itemList.add(item);
        item = new StockItem("20", "AUD", "Australian Dollar", 1, "");
        itemList.add(item);                
        item = new StockItem("21", "AUR", "Gold", 1, "Gramm");//CBRF
        itemList.add(item);
        item = new StockItem("22", "ARG", "Silver", 1, "Gramm");//CBRF
        itemList.add(item);
        item = new StockItem("23", "PT", "Platinum", 1, "Gramm");//CBRF
        itemList.add(item);
        item = new StockItem("24", "PD", "Palladium", 1, "Gramm");//CBRF
        itemList.add(item);
        item = new StockItem("1006", "brent", "ICE.Brent", 1, "Barrel");
        itemList.add(item);
        item = new StockItem("10", "AU", "Gold", 1, "Troy ounce");
        itemList.add(item);
        item = new StockItem("1500", "AL", "Aluminum", 1, "Tonne");
        itemList.add(item);
        item = new StockItem("1501", "CU", "Copper", 1, "Tonne");
        itemList.add(item);
        item = new StockItem("1502", "NI", "Nickel", 1, "Tonne");
        itemList.add(item);
        item = new StockItem("1503", "SN", "Tin", 1, "Tonne");
        itemList.add(item);
        item = new StockItem("1504", "PD", "Palladium", 1, "Troy ounce");
        itemList.add(item);
        item = new StockItem("1505", "PT", "Platinum", 1, "Troy ounce");
        itemList.add(item);
        item = new StockItem("1506", "AG", "Silver", 1, "Troy ounce");
        itemList.add(item);
        item = new StockItem("1507", "ZN", "Zinc", 1, "Tonne");
        itemList.add(item);
    }

    /**
     * Get StockItemStore
     *
     * @return StockItemStore
     */
    public static StockItemStore Instance() {
        return new StockItemStore();
    }

    /**
     * Get StockItem from StockItemStore by id
     *
     * @param id
     * @return StockItem
     */
    public StockItem findById(String id) {
        for (StockItem item : itemList) {
            if (id.equals(item.getId())) {
                return item;
            }
        }
        return null;
    }

    /**
     * Get StockItem from StockItemStore by code
     *
     * @param code
     * @return StockItem
     */
    public StockItem findByCode(String code) {
        for (StockItem item : itemList) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }
    
    /**
     * Get StockItem from StockItemStore by code and nominal name
     *
     * @param code
     * @return StockItem
     */
    public StockItem findByCodeAndNominalName(String code, String nominal) {
        for (StockItem item : itemList) {
            if (item.getCode().equals(code) && item.getnominalName().equals(nominal)) {
                return item;
            }
        }
        return null;
    }
}
